package com.jin.flashsaled.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import com.jin.flashsaled.entity.Goods;

import com.jin.flashsaled.result.Good;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 靳鹏宇
 * @since 2025-09-18
 */

@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {
    /**
     * Lambda 只负责 WHERE；JOIN 和字段写死
     */
    @Select("SELECT g.*, " +
            "       s.seckill_price  AS seckill_price, " +
            "       s.stock_count    AS stock_count, " +
            "       s.start_date     AS start_date, " +
            "       s.end_date       AS end_date " +
            "FROM goods g " +
            "LEFT JOIN seckill_goods s ON g.id = s.goods_id " +
            "${ew.customSqlSegment}")
    List<Good> selectGoodsWithSeckill(@Param(Constants.WRAPPER) Wrapper<Goods> wrapper);

}
